# -*- coding: utf-8 -*-
# @Time : 2024/1/31 9:37
# @Author : ZH
# @File : 35.py
# @Software: PyCharm

class Solution(object):
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        # z_index = int(len(nums)/2) + 1
        l_index = 0
        r_index = len(nums) - 1
        if nums[0] > target: return 0
        # if nums[-1] < target: return len(nums)
        # if nums[-1] == target: return len(nums) - 1
        while r_index > l_index:
            z_index = int((r_index + l_index) / 2)
            # print(l_index, r_index,z_index)
            if nums[z_index] == target:
                return z_index
            if nums[z_index] < target:
                l_index = z_index + 1

            else:
                r_index = z_index - 1

        return l_index

if __name__ == '__main__':
    so = Solution()
    z = so.searchInsert([1, 3], 2)
    print(z)
